const http = require("http");
const url = require("url");
//引入事件类
const EventEmiter = require("events");

//实例化自定义事件对象
let routeEvent = new EventEmiter();
//引入routes路由
let routes = require("./routes.js");
routes(routeEvent);

let server = http.createServer((req, res) => {
  res.setHeader("content-type", "text/html;charset=utf-8");
  let urlObj = url.parse(req.url, true);
  let pathname = urlObj.pathname;
  routeEvent.emit(pathname, req, res);
});
server.listen(8989);
